
from base_db import Influxdb_info
from influxdb import InfluxDBClient
import search_db
'''
Author: Guoliang Liu
Date: 20230506
'''
def delete_num(IP, PID, IDS):
    # cd = create_data()
    # 需要造数的机器IP （也是数据库IP）
    influxDB_IP = IP
    # 工程 ID
    measurement_value = PID
    # 数据点对应 ids
    path_value = IDS
    db_info = Influxdb_info()
    influxDB_name = db_info.get_influxDB_name()
    influxDB_table = db_info.get_influxDB_table()
    password_db = db_info.get_influxDB_password()

    print("[INFO] 删除数据所在机器：" + influxDB_IP)
    # 连接数据库
    client = InfluxDBClient(influxDB_IP, 8086, influxDB_name, password_db, influxDB_table, ssl=True)
    search_db.search_data(measurement_value, path_value, client, influxDB_table)
    sql = "delete FROM \"" + measurement_value + "\" WHERE Path='" + path_value + "';"
    client.query(
        sql,
        database=influxDB_table)
    print("[INFO] " + path_value + " 数据删除成功")
    search_db.search_data(measurement_value, path_value, client, influxDB_table)
    client.close()

# delete_num()